package com.hammer.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.walixiwa.floatingsearchview.FloatingSearchView;
import com.walixiwa.floatingsearchview.suggestions.model.SearchSuggestion;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {
    private FloatingSearchView floatingSearchView;
    private List<HistorySuggestion> suggestionList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initSearchView();

    }

    private void initSearchView() {
        suggestionList.add(new HistorySuggestion("测试1"));
        suggestionList.add(new HistorySuggestion("测试2"));
        suggestionList.add(new HistorySuggestion("测试3"));

        floatingSearchView = findViewById(R.id.floating_search_view);

        /*floatingSearchView.attachNavigationDrawerToMenuButton(drawerLayout);*/
        floatingSearchView.setOnQueryChangeListener((oldQuery, newQuery) -> {

        });
        floatingSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
            @Override
            public void onSuggestionClicked(SearchSuggestion searchSuggestion) {

            }

            @Override
            public void onSearchAction(String currentQuery) {

            }
        });
        floatingSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
            @Override
            public void onFocus() {
                //setStatusBarDim(true);
                floatingSearchView.swapSuggestions(suggestionList);
            }

            @Override
            public void onFocusCleared() {
                //setStatusBarDim(false);
                floatingSearchView.clearSuggestions();
            }
        });

        floatingSearchView.setOnBindSuggestionCallback((suggestionView, leftIcon, textView, item, itemPosition) -> {
            suggestionView.setOnClickListener(view -> {
                floatingSearchView.setSearchHint(item.getBody());
                floatingSearchView.clearSuggestions();
                floatingSearchView.clearSearchFocus();
            });
        });

        floatingSearchView.setOnMenuItemClickListener(item -> {
            if (item.getItemId() == R.id.more) {
                /* addFragment("引擎5", null, null);*/
            }
        });
    }
}
